AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')
	
ENT.Name = "Ghoul"
ENT.Hand = "Blood_Left"
ENT.AnimScale = 4
ENT.Bloody = true
ENT.Damage = 35
ENT.DoorDamage = 10
ENT.Pain = Vo.Ghoul_P
ENT.Death = Vo.Ghoul_D
ENT.Taunt = Vo.Ghoul_T
ENT.Attack = {"npc/zombie/zo_attack1.wav","npc/zombie/zo_attack2.wav"}
ENT.AttackAnims = {"attackA","attackB","attackC"}

function ENT:Initialize()

	self:SetModel( "models/zombie/classic.mdl" )
	util.PrecacheSound("npc/zombie/zo_attack1.wav")
	util.PrecacheSound("npc/zombie/zo_attack2.wav")
	
	self:SetHullType( HULL_HUMAN );
	self:SetHullSizeNormal();
	
	self:SetSolid( SOLID_BBOX ) 
	self:SetMoveType( MOVETYPE_STEP )
	
	self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_AIM_GUN )
	
	self:SetMaxYawSpeed( 5000 )
	
	//don't touch stuff above here
	self:SetHealth(math.random(90,110))
	self.MaxHealth = 110

end

function ENT:SelectSchedule()

	local schdChase = ai_schedule.New( "AIFighter Chase" ) //creates the schedule used for this npc
	
	schdChase:AddTask( "FindEnemy", 		{ Class = "player", Radius = 200000 } )
	schdChase:EngTask( "TASK_GET_PATH_TO_ENEMY", 0 )
    schdChase:EngTask( "TASK_RUN_PATH_TIMED", 0.2 )
    schdChase:EngTask( "TASK_WAIT", 0.2 ) 
	
	local close = false
	local tbl = team.GetPlayers(TEAM_HUMANS)
	table.Add(tbl,ents.FindByClass("prop_door_rotating"))
	table.Add(tbl,ents.FindByModel("models/props_debris/wood_chunk03a.mdl"))
	table.Add(tbl,ents.FindByModel("models/props_debris/wood_chunk03b.mdl"))
	table.Add(tbl,ents.FindByClass("func_breakable"))
	for k,v in pairs(tbl) do
		if v:GetPos():Distance(self:GetPos()) < 100 then
			close = true
		end
	end

	if close then
		schdChase:EngTask( "TASK_STOP_MOVING", 			0 )
		schdChase:EngTask( "TASK_FACE_ENEMY", 			0 )
		schdChase:AddTask( "PlaySequence", 				{ Name = ChooseRandom(self.AttackAnims), Speed = .9 } )
	end

	self:StartSchedule( schdChase ) 

end